package com.entropy.code.service.impl;

import com.entropy.code.dal.model.UserPO;
import com.entropy.code.dto.UserDTO;
import com.entropy.code.repository.UserRepository;
import com.entropy.code.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xiachao
 * @date 2022-01-26
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserRepository userRepository;

    @Override
    public boolean addUser(UserDTO dto) {
        UserPO po = new UserPO();
        BeanUtils.copyProperties(dto, po);
        return this.userRepository.addUser(po) > 0;
    }

    @Override
    public UserDTO getByUid(Long uid) {
        UserPO po = this.userRepository.getByUid(uid);
        if (po == null) {
            return null;
        }
        UserDTO dto = new UserDTO();
        BeanUtils.copyProperties(po, dto);
        return dto;
    }
}
